package org.dromara.comm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.comm.domain.AsServiceChannels;
import org.dromara.comm.domain.AsServicePlatformEchoDisplay;
import org.dromara.comm.mapper.AsServiceChannelsMapper;
import org.dromara.comm.mapper.AsServicePlatformEchoDisplayMapper;
import org.dromara.comm.service.AsServicePlatformEchoDisplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询添加的服务指南
 *
 * @author: 郭伟明
 * @date: 2024-07-31 16:12
 **/
@Service
public class AsServicePlatformEchoDisplayServiceImpl extends ServiceImpl<AsServicePlatformEchoDisplayMapper, AsServicePlatformEchoDisplay> implements AsServicePlatformEchoDisplayService {

    @Autowired
    private AsServicePlatformEchoDisplayMapper asServicePlatformEchoDisplayMapper;

    @Autowired
    private AsServiceChannelsMapper asServiceChannelsMapper;

    /**
     * 查询已添加服务指南
     * @param asServiceChannels
     * @return
     */
    @Override
    public List<Map<String, Object>> guideAll(AsServiceChannels asServiceChannels) {
        List<Map<String, Object>> arrayList = new ArrayList<>();
        List<AsServiceChannels> serviceChannels = asServiceChannelsMapper.selectList(null);

        for (AsServiceChannels serviceChannel : serviceChannels) {
            LambdaQueryWrapper<AsServicePlatformEchoDisplay> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(AsServicePlatformEchoDisplay::getCategoryId, serviceChannel.getId());
            List<AsServicePlatformEchoDisplay> asServicePlatforms = asServicePlatformEchoDisplayMapper.selectList(wrapper);

            if (!asServicePlatforms.isEmpty()) {
                Map<String, Object> channelMap = new HashMap<>();
                channelMap.put("id", serviceChannel.getId());
                channelMap.put("isDelete", serviceChannel.getIsDelete());
                channelMap.put("categoryName", serviceChannel.getCategoryName());
                channelMap.put("asServicePlatforms", asServicePlatforms);

                Map<String, Object> result = new HashMap<>();
                result.put("serviceChannel", channelMap);

                arrayList.add(result);
            }
        }

        return arrayList;
    }

    /**
     * 查询已添加服务指南详情
     *
     * @param id
     * @return
     */
    @Override
    public AsServicePlatformEchoDisplay selectAsServicePlatformEchoDisplayById(Integer id) {
        return asServicePlatformEchoDisplayMapper.selectById(id);
    }

}
